package org.jks.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.jks.model.WorkType;
import org.jks.service.WorkTypeService;
import org.jks.util.PrintUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/worktype")
public class WorkTypeController {
	@Autowired
	WorkTypeService workTypeService;

	@RequestMapping("/add")
	public void add(WorkType workType, HttpServletRequest request,
			HttpServletResponse response) {
		try {
			workTypeService.save(workType);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/delete")
	public void delete(long id, HttpServletRequest request, HttpServletResponse response){
		try{
			workTypeService.delete(id);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/update")
	public void update(WorkType workType, HttpServletRequest request, HttpServletResponse response){
		try{
			workTypeService.update(workType);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/all")
	public void all(HttpServletRequest request, HttpServletResponse response){
		try{
			List<WorkType> workTypes = workTypeService.all();
			PrintUtil.print(workTypes);
		}
		catch(Exception e){
			e.printStackTrace();
		}
	}
}
